#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
int main(int argc,char *argv[])
{
	if(argc == 1)
	{
		char buf[512];
		int count;
		while(count = read(0,buf,512))
			write(1,buf,count);
	}
	else
	{
		if(argv[1][0]!='>'&&argv[1][0]!='<')
		{
			char str[10000];
			int file = open(argv[1],O_CREAT|O_RDWR,0666);
			if(file == -1)
			{
				printf("can not find this file");
				return 0;
			}
			while(1)
			{
				int ret = 0;
				ret = read(file,str,10000);
				if(ret <= 0)
					break;
			}
			printf ("%s\n",str);
			close(file);
		}
		else
		{
			char buf[100];
			char temp[10000];
			int i=1;
			for(i=1;argv[1][i]!='\0';i++)
			{
				buf[i-1]=argv[1][i];
			}
			buf[i]='\0';
			int file = open(buf,O_CREAT|O_RDWR,0666);
			if(file == -1)
			{
				printf("can not open this file");
				return 0;
			}
			if(argv[1][0]=='>')	
				dup2(file,1);
				
			else		
				dup2(file,0);
			close(file);
			int count;
			while(count = read(0,temp,10000))
				write(1,temp,count);
		
		}
		
	}

	return 0;
}
